#!/usr/bin/env bash

# __version__ = "$Revision$"
# Last Modified on $Date$
# by $Author$
# from $Source$

project_name=sarada

#SCRIPTS_DIR should be defined in your environment
CWD=${SCRIPTS_DIR}/${project_name}
LOG=${CWD}/logs/commit_to_googlecode.log

#redirect all stdout and stderr to LOG
#exec >> $LOG 2>&1

echo "--------------------------------------------------------------"
echo "`date` - Started the script"

if [ -d ${CWD}/.hg ]
then
  cd ${CWD}
else
  echo "${CWD} doesn't exist or is not a hg repo"
  exit 1
fi

cp ~/.hgrc dot_hgrc.txt
cp ~/.hgignore dot_hgignore.txt
cp /media/OS/CodeBlocks/default.conf codeblocks.default.conf

hg addremove -s 50
hg commit -m "auto-commit"
hg fetch https://dkmurthy9:${DKMURTHY_GOOGLECODE_PASSWD}@${project_name}.googlecode.com/hg/
hg push https://dkmurthy9:${DKMURTHY_GOOGLECODE_PASSWD}@${project_name}.googlecode.com/hg/

tar --exclude .hg --exclude ${project_name}.tar -cf ${project_name}.tar ../${project_name}
gzip ${project_name}.tar

python googlecode_upload.py -s "all scripts" -p ${project_name} -l Featured -u dkmurthy9 -w ${DKMURTHY_GOOGLECODE_PASSWD} ${project_name}.tar.gz

rm ${project_name}.tar.gz

echo "`date` - Finished the script"
